home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_04
/
1004046a
< prev
next >
Wrap
Text File
|
1992-02-11
|
29KB
|
625 lines
/*
menu = controls cursor movement and menu display and selection -
returns the number of the selected menu item.
values: a string consisting of two digits showing
the number of menu choices, followed by
four digits for each choice, the first
two showing the starting column of the
menu item and the second two its length.
menu_first_line: the first line of instructions in the
menu mode.
menu_second_line: the second line in the menu mode. It con-
tains the menu choices.
screen_first_line: the first line of instructions in the
screen mode.
screen_second_line: the second line of instructions in the
screen mode.
menu_type: 0: Start with Menu Mode.
Alphanumeric characters are ignored
when entered in screen mode.
1: Start with Menu Mode.
Alphanumeric characters are displayed
when entered in screen mode
2: Start with Screen Mode.
Alphanumeric characters are ignored
when entered in screen mode.
3: Start with Screen Mode.
Alphanumeric characters are displayed
when entered in screen mode.
screen_color: color for screen mode.
menu_color: color for menu display.
highlight_color: color of selected menu item
select_no: number of menu items using selection
escape_char: number of the key selected for escape
from the screen display.
map: bit map of permitted cursor locations.
The cursor will go to permitted locations
only and no others.
*/
int menu(char values[],char menu_first_line[],char menu_second_line[],
char screen_first_line[],char screen_second_line[],int menu_type,
int screen_color,int menu_color,int highlight_color, int select_no,
int escape_char, int first_line_loc, char map[25][10])
{
union REGS reg;
int i,choices,indx,start,length,menu_second_line_length;
int interim,remainder,temp;
char spaces[80],prev_char;
for (i=0; i<76; i++)
spaces[i] = ' ';
spaces[76] = '\0';
menu_second_line_length = strlen(menu_second_line);
gotoxy(2,first_line_loc);
choice = 1;
if (menu_type <= 1)
{
color_printf("%s",menu_color,menu_first_line);
gotoxy(2,first_line_loc+1);
length = values[4] - '0';
length = 10 * length + values[5] - '0';
for (indx = 0; indx < menu_second_line_length; indx++)
if (indx < length)
putcolorchar(menu_second_line[indx],
highlight_color);
else
putcolorchar(menu_second_line[indx],
menu_color);
}
else
{
color_printf(screen_first_line,menu_color);
gotoxy(2,first_line_loc+1);
color_printf(screen_second_line,menu_color);
}
choices = 10 * (values[0] - '0') + values[1] -'0';
gotoxy(column,row);
for(;;)
{
key_id = getch();
if (key_id == 0)
key_id = getch()+256;
if (menu_type <= 1)
{
switch(key_id)
{
case 13:
if(choice > select_no)
goto ExitPoint;
change_line_color(47);
gotoxy(2,23);
color_printf("%s",screen_color,spaces);
gotoxy(2,23);
color_printf("%s",menu_color,
screen_first_line);
gotoxy(2,24);
color_printf("%s",screen_color,spaces);
gotoxy(2,24);
color_printf("%s",menu_color,
screen_second_line);
gotoxy(column,row);
menu_type +=2;
break;
case 333: /*Right Arrow*/
choice = choice + 2;
case 331: /*Left Arrowb*/
--choice;
if (choice < 1)
choice = choices;
if (choice > choices)
choice = 1;
start = 10 * (values[(choice-1)*4+2] - '0')
+values[(choice-1)*4+3] - '0';
length = 10 * (values[(choice-1)*4+4] - '0')
+values[(choice-1)*4+5] - '0';
gotoxy(2,24);
for (indx = 0;indx < menu_second_line_length;
indx++)
{
if ((indx >= start) && (indx < start
+ length))
putcolorchar
(menu_second_line
[indx],
highlight_color);
else
putcolorchar
(menu_second_line
[indx],
menu_color);
}
gotoxy(column,row);
break;
default:
if ((key_id >= 0x41) && (key_id <= 0x7A))
{
temp = toupper(key_id);